using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PBR.Controls
{
    public partial class SegmentPropertiesControl : UserControl
    {
        #region Member Variables

        private Scene scene;
        private MainForm mainForm;

        #endregion

        #region Member Functions
        
        public SegmentPropertiesControl(Scene scene, MainForm mainForm)
        {
            InitializeComponent();

            this.scene = scene;
            this.mainForm = mainForm;
        }

        public void InitSegment()
        {
            Material material = scene.SelectedMat;

            selectedMatLabel.Text = material.Name;

            strokeLengthScrollBar.Value = (int)material.BaseStrokeLength;
            strokeLengthNumericUpDown.Value = (int)material.BaseStrokeLength;

            absEdgeThreshScrollBar.Value = material.EdgeThreshAbs;
            absEdgeThreshNumericUpDown.Value = material.EdgeThreshAbs;

            relEdgeThreshScrollBar.Value = material.EdgeThreshRel;
            relEdgeThreshNumericUpDown.Value = material.EdgeThreshRel;

            relEdgeScaleNumericUpDown.Value = material.EdgeScaleRel;
            relEdgeScaleScrollBar.Value = material.EdgeScaleRel;

            edgeLevelScrollBar.Value = material.EdgeLevel;
            edgeLevelNumericUpDown.Value = material.EdgeLevel;

            overlapScrollBar.Value = material.Overlap;
            overlapNumericUpDown.Value = material.Overlap;

            opacityScrollBar.Value = material.Opacity;
            opacityNumericUpDown.Value = material.Opacity;

            numBrushStrokesNumericUpDown.Value = scene.Renderer.Painter.BaseIterations;
        }

        #endregion

        #region Stroke Length

        private void strokeLengthNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if(scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.BaseStrokeLength = (int) strokeLengthNumericUpDown.Value;
            strokeLengthScrollBar.Value = (int) strokeLengthNumericUpDown.Value;
        }

        private void strokeLengthScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.BaseStrokeLength = (int)strokeLengthScrollBar.Value;
            strokeLengthNumericUpDown.Value = (int)strokeLengthScrollBar.Value;
        }

        #endregion

        #region Abs Edge Thresh

        private void absEdgeThreshScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeThreshAbs = (byte)absEdgeThreshScrollBar.Value;
            absEdgeThreshNumericUpDown.Value = (int)absEdgeThreshScrollBar.Value;
        }

        private void absEdgeThreshNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeThreshAbs = (byte)absEdgeThreshNumericUpDown.Value;
            absEdgeThreshScrollBar.Value = (int)absEdgeThreshNumericUpDown.Value;
        }

        #endregion

        #region Rel Edge Thresh

        private void relEdgeThreshScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeThreshRel = (byte)relEdgeThreshScrollBar.Value;
            relEdgeThreshNumericUpDown.Value = (int) relEdgeThreshScrollBar.Value;
        }

        private void relEdgeThreshNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeThreshRel = (byte)relEdgeThreshNumericUpDown.Value;
            relEdgeThreshScrollBar.Value = (int) relEdgeThreshNumericUpDown.Value;
        }

        #endregion

        #region Rel Edge Scale

        private void relEdgeScaleScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeScaleRel = (int)relEdgeScaleScrollBar.Value;
            relEdgeScaleNumericUpDown.Value = (int)relEdgeScaleScrollBar.Value;
        }

        private void relEdgeScaleNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeScaleRel = (int)relEdgeScaleNumericUpDown.Value;
            relEdgeScaleScrollBar.Value = (int)relEdgeScaleNumericUpDown.Value;
        }

        #endregion

        #region Edge Level

        private void edgeLevelScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeLevel = (int)edgeLevelScrollBar.Value;
            edgeLevelNumericUpDown.Value = (int)edgeLevelScrollBar.Value;
        }

        private void edgeLevelNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.EdgeLevel = (int)edgeLevelNumericUpDown.Value;
            edgeLevelScrollBar.Value = (int)edgeLevelNumericUpDown.Value;
        }

        #endregion

        #region Overlap

        private void overlapScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.Overlap = (int)overlapScrollBar.Value;
            overlapNumericUpDown.Value = (int)overlapScrollBar.Value;
        }

        private void overlapNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.Overlap = (int)overlapNumericUpDown.Value;
            overlapScrollBar.Value = (int)overlapNumericUpDown.Value;
        }

        #endregion

        #region Opacity

        private void opacityScrollBar_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.Opacity = (int)opacityScrollBar.Value;
            opacityNumericUpDown.Value = (int)opacityScrollBar.Value;
        }

        private void opacityNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            if (scene.SelectedMat == null)
            { return; }
            scene.SelectedMat.Opacity = (int)opacityNumericUpDown.Value;
            opacityScrollBar.Value = (int)opacityNumericUpDown.Value;
        }

        #endregion

        #region Global Number of Brush Strokes

        private void numBrushStrokesNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            scene.Renderer.Painter.BaseIterations = (int) numBrushStrokesNumericUpDown.Value;
        }

        #endregion





    }
}

